﻿using SDFL.Core.DataStructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Test_SDFL_GeneralFunc
{
    
    
    /// <summary>
    ///This is a test class for StackTest and is intended
    ///to contain all StackTest Unit Tests
    ///</summary>
    [TestClass()]
    public class StackTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Push
        ///</summary>
        public void PushTestHelper<T>()
        {
            Stack<T> target = new Stack<T>(); // TODO: Initialize to an appropriate value
            T item = default(T); // TODO: Initialize to an appropriate value
            target.Push(item);
            T actual = target.Pop();
            Assert.AreEqual(item, actual); 
        }

        [TestMethod()]
        public void PushTest()
        {
            PushTestHelper<string>();
            PushTestHelper<int>();
            PushTestHelper<bool>();
        }

        /// <summary>
        ///A test for Pop
        ///</summary>
        public void PopTestHelper<T>()
        {
            Stack<T> target = new Stack<T>(); // TODO: Initialize to an appropriate value
            T expected = default(T); // TODO: Initialize to an appropriate value
            target.Push(expected);
            T actual;
            actual = target.Pop();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void PopTest()
        {
            PopTestHelper<string>();
            PopTestHelper<int>();
            PopTestHelper<double>();
        }

        /// <summary>
        ///A test for Stack`1 Constructor
        ///</summary>
        public void StackConstructorTest1Helper<T>()
        {
            Stack<T> target = new Stack<T>();
            T item = default(T);

            for (int i = 0; i < 256; i++)
            {
                target.Push(item);
            }

            try
            {
                target.Push(item);
            }
            catch (System.StackOverflowException)
            {
                Assert.IsTrue(true, "The default Stack size if 256, we get StackOverflowException");
            }
        }

        [TestMethod()]
        public void StackConstructorTest1()
        {
            StackConstructorTest1Helper<string>();
            StackConstructorTest1Helper<int>();
        }

        /// <summary>
        ///A test for Stack`1 Constructor
        ///</summary>
        public void StackConstructorTestHelper<T>()
        {
            int size = 10; // TODO: Initialize to an appropriate value
            Stack<T> target = new Stack<T>(size);
            T item = default(T);

            try
            {
                for (int i = 0; i < 11; i++)
                {
                    target.Push(item);
                }
            }
            catch (System.StackOverflowException)
            {
                Assert.IsTrue(true, "The default Stack size if 256, we get StackOverflowException");
            }
        }

        [TestMethod()]
        public void StackConstructorTest()
        {
            StackConstructorTestHelper<string>();
            StackConstructorTestHelper<int>();
        }

        /// <summary>
        ///A test for Push
        ///</summary>
        public void PushTest1Helper<T>()
        {
        //    Stack<T> target = new Stack<T>(); // TODO: Initialize to an appropriate value
        //    Stack<T> aimStack = null; // TODO: Initialize to an appropriate value
        //    T[] items = null; // TODO: Initialize to an appropriate value
        //    target.Push(aimStack, items);
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //
        }

        [TestMethod()]
        public void PushTest1()
        {
            Stack<int> x = new Stack<int>(100);
            
            x.Push(x, 1, 2, 3, 4, 5);

            int[] expected = new int[100];

            for (int i = 0; i < 5; i++)
            {
                expected[i] = x.Pop();
                Assert.AreEqual(expected[i], 5-i);
            }
        }
    }
}
